import React from 'react';
import ReactDOM from 'react-dom';
import './style.scss';
// import Home from './app/home/home';
import Me from './app/me/me';
import registerServiceWorker from './registerServiceWorker';
import {
    // HashRouter as Router,
    BrowserRouter as Router,
    Route
} from 'react-router-dom';
import routes from './routings';
// import Tabbar from './app/components/tabbar/tabbar';
import axios from 'axios';
import 'react-flexible';
import Message from './app/components/message/message';

window.$http = axios;
window.$apiUrl = process.env.PUBLIC_URL.API_URL + process.env.PUBLIC_URL.PREFIX;
window.$url = process.env.PUBLIC_URL.API_URL;

const RouteWithSubRoutes = (route) => (
    <Route path={route.path} render={props => (
      // pass the sub-routes down to keep nesting
      <route.component {...props} routes={route.routes}/>
    )}/>
  )

/**
 * 初始化页面
 */
const init = () => {
    /* const RouteConfigExample = () => {
        return (
        <Router>
            <div>
            <Route exact path="/" component={Home}/>
            {routes.map((route, i) => (
                <RouteWithSubRoutes key={i} {...route}/>
            ))}
            <Tabbar />
            </div>
        </Router>
    )} */
    const RouteConfigExample = () => {
        return (
        <Router>
            <div>
            <Message></Message>
            <Route exact path="/" component={Me}/>
            {routes.map((route, i) => (
                <RouteWithSubRoutes key={i} {...route}/>
            ))}
            </div>
        </Router>
    )}

    ReactDOM.render(<RouteConfigExample />, document.getElementById('root'));
}

init();
registerServiceWorker();
